package com.iams.manage.instener;


import com.iams.common.utils.DateUtils;
import com.iams.common.utils.spring.SpringUtils;
import com.iams.manage.domain.BorrowRecord;
import com.iams.manage.mapper.BorrowApprovalMapper;
import com.iams.manage.service.IBorrowRecordService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class BorrowApprovalEndListener implements ExecutionListener{


    @Override
    public void notify(DelegateExecution delegateExecution){

        String instanceId = delegateExecution.getProcessInstanceId();
        String businessKey = delegateExecution.getProcessInstanceBusinessKey();

        // 通过instanceId和businessKey查询applyId, 查找borrowRecord
        BorrowApprovalMapper borrowApprovalMapper = SpringUtils.getBean(BorrowApprovalMapper.class);
        Long applyId = borrowApprovalMapper.selectApplyIdByBusinessKey(businessKey);

        BorrowRecord borrowRecord = SpringUtils.getBean(IBorrowRecordService.class).selectBorrowRecordById(applyId);
        borrowRecord.setBorrowDate(DateUtils.getNowDate());
        SpringUtils.getBean(IBorrowRecordService.class).updateBorrowRecord(borrowRecord);
    }
}
